#include "client2.h"
#include "ui_client2.h"
#include "client.h"
#include "client2.h"

client2::client2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::client2)
{
    ui->setupUi(this);
    setWindowTitle(tr("注册"));
    ui->lineEdit_5->setEchoMode(QLineEdit::Password);
}

client2::~client2()
{
    delete ui;
}
//记住密码
void client2::on_checkBox_clicked()
{
    static int flag =1;
    if(flag)
    {
        ui->lineEdit_5->setEchoMode(QLineEdit::Normal);
        flag=0;
    }
    else
    {
        ui->lineEdit_5->setEchoMode(QLineEdit::Password);
        flag=1;
    }

}
//关闭窗口
void client2::on_pushButton_6_clicked()
{
    close();
}

//调用数据库进行注册
QString client2::on_pushButton_5_clicked()
{
    //-------------------------------------------------------------------------------------
    //数据库处理
    QSqlDatabase db1 = QSqlDatabase::database("connection1"); //得到指定连接名称数据库

    QSqlQuery query1(db1);
    query1.exec("select * from data1"); //执行sql语句
    //---------------------------------------------------------------------------------------
    //将注册的账号存入数据库
    query1.prepare("insert into data1(id, mima) values(?, ?)");
    QString mimaValue = ui->lineEdit_5->text();
    QString idValue = ui->lineEdit->text();
    query1.addBindValue(idValue);
    query1.addBindValue(mimaValue);
    query1.exec(); //执行插入语句
    query1.exec("select * from student"); //执行查询语句
    query1.seek(-1); //回到初始位置，即第一个数据的前一个位置

    close();
    return idValue;
}
QString client2::Returnid()
{
    QString idValue = ui->lineEdit->text();
    return idValue;
}

